package com.sskj.hangqing.presenter;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.hangqing.bean.HangqingBannerBean;
import com.sskj.hangqing.bean.ZixunListBean;
import com.sskj.hangqing.http.HttpConfig;
import com.sskj.hangqing.ui.fragment.ZixunListFragment;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;

import java.util.List;

import io.reactivex.Flowable;


public class ZixunListFragmentPresenter extends BasePresenter<ZixunListFragment> {

    public Flowable<List<ZixunListBean>> getData(String page) {
        return httpService.getZixunList(page)
                .converter(new JsonConverter<HttpData<PageBean<ZixunListBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(pageBeanHttpData -> pageBeanHttpData.getData().getList());
    }

    public void getBanner() {
        httpService.getBanner("3")
                .execute(new JsonCallBack<HttpData<List<HangqingBannerBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<HangqingBannerBean>>> response) {
                        HttpData<List<HangqingBannerBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.updateBanner(httpData.getData());
                        }
                    }
                });
    }

}
